package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.SportDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.OrderSetting;
import com.itheima.pojo.Sport;
import com.itheima.service.SportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service(interfaceClass = SportService.class)
@Transactional
public class SportServiceImpl implements SportService {
   @Autowired
   private SportDao sportDao;

   @Override
    public void upload(List<Sport> list) {
       for (Sport sport : list) {
           sportDao.upload(sport);
       }
    }

    //增加
    public void add(Sport sport) {
        sportDao.add(sport);
    }

    //删除
    public void delete(Integer id) {
        sportDao.delete(id);
    }

    //修改
    public void update(Sport sport) {
        sportDao.update(sport);
    }

    //分页查询
   /* public PageResult findPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        Page<Sport>page=sportDao.selectByCondition(queryPageBean);
        return new PageResult(page.getTotal(),page.getResult());
    }*/


    public PageResult findPage(QueryPageBean queryPageBean){
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        if (queryString!=null){
            queryString="%"+queryString+"%";
            queryPageBean.setQueryString(queryString);
        }
        PageHelper.startPage(currentPage,pageSize);
        List<Sport> sport= sportDao.findPage(queryPageBean);
        PageInfo<Sport> page=new PageInfo<Sport>(sport);

        return  new PageResult(page.getTotal(),page.getList());
    }
}
